package leetcode_1_200;

import node.ListNode;

import java.util.HashSet;
import java.util.Set;

public class LeeCode_142 {
    public static void main(String[] args) {

    }
    public ListNode detectCycle(ListNode head) {
        Set<ListNode> set = new HashSet<>();
        while (head != null){
            if (set.contains(head))
                return head;
            set.add(head);
            head = head.next;
        }
        return null;
    }
}
